package p100;

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

public class Leetcode_128 {
    public static int longestConsecutive(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }
        AtomicInteger result = new AtomicInteger();
        set.forEach(v -> {
            if (!set.contains(v - 1)) {
                int count = 1;
                while (set.contains(v + 1)) {
                    v++;
                    count++;
                }
                result.set(Math.max(count, result.get()));
            }
        });
        return result.get();
    }

    public static void main(String[] args) {

    }
}
